2020-2021 Sunseeker Telemetry and Lighting System
pmap_ex3_singleFunctionToMultiplePins.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
66 //******************************************************************************
67 #include "driverlib.h"
68 //*****************************************************************************
69 //
70 //Refer Datasheet for Port4 Port Mapping definitions
71 //
72 //*****************************************************************************
73 uint8_t port_mapping[] = {
74  //Port 4
75  PM_TB0CCR1A,
76  PM_TB0CCR2A,
77  PM_TB0CCR3A,
78  PM_TB0CCR4A,
79  PM_TB0CCR1A,
80  PM_TB0CCR2A,
81  PM_TB0CCR3A,
82  PM_TB0CCR4A
83 };
84 
85 void main (void)
86 {
87  //Stop WDT
88  WDT_A_hold(WDT_A_BASE);
89 
90  //Set DCO FLL reference = REFO
91  UCS_initClockSignal(
92  UCS_FLLREF,
93  UCS_REFOCLK_SELECT,
94  UCS_CLOCK_DIVIDER_1
95  );
96 
97  //REFO Clock Sources ACLK
98  UCS_initClockSignal(
99  UCS_ACLK,
100  UCS_REFOCLK_SELECT,
101  UCS_CLOCK_DIVIDER_1
102  );
103 
104  //Set Ratio and Desired MCLK Frequency and initialize DCO
105  UCS_initFLLSettle(
106  1048,
107  32
108  );
109 
110 
111  //Setup Port Pins
112  //P4.0 - P4.7 output
113  //P4.0 - P4.6 Port Map functions
114  GPIO_setAsPeripheralModuleFunctionOutputPin(
115  GPIO_PORT_P4,
116  GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
117  GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
118  GPIO_PIN6 + GPIO_PIN7 + GPIO_PIN8 +
119  GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
120  GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 +
121  GPIO_PIN15
122  );
123 
124  //Start Up Down Timer
125  Timer_B_initUpDownModeParam initUpDownModeParam = {0};
126  initUpDownModeParam.clockSource = TIMER_B_CLOCKSOURCE_ACLK;
127  initUpDownModeParam.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1;
128  initUpDownModeParam.timerPeriod = 256;
129  initUpDownModeParam.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_DISABLE;
130  initUpDownModeParam.captureCompareInterruptEnable_CCR0_CCIE =
131  TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE;
132  initUpDownModeParam.timerClear = TIMER_B_SKIP_CLEAR;
133  initUpDownModeParam.startTimer = true;
134  Timer_B_initUpDownMode(TIMER_B0_BASE, &initUpDownModeParam);
135 
136  //Generate PWM 1
137  Timer_B_initCompareModeParam param = {0};
138  param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_1;
139  param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
140  param.compareOutputMode = TIMER_B_OUTPUTMODE_TOGGLE_SET;
141  param.compareValue = 192;
142  Timer_B_initCompareMode(TIMER_B0_BASE, &param);
143 
144  //Generate PWM 2
145  param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_2;
146  param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
147  param.compareOutputMode = TIMER_B_OUTPUTMODE_TOGGLE_SET;
148  param.compareValue = 128;
149  Timer_B_initCompareMode(TIMER_B0_BASE, &param);
150 
151  //Generate PWM 3
152  param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_3;
153  param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
154  param.compareOutputMode = TIMER_B_OUTPUTMODE_TOGGLE_SET;
155  param.compareValue = 64;
156  Timer_B_initCompareMode(TIMER_B0_BASE, &param);
157 
158  //Generate PWM 4
159  param.compareRegister = TIMER_B_CAPTURECOMPARE_REGISTER_4;
160  param.compareInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE;
161  param.compareOutputMode = TIMER_B_OUTPUTMODE_TOGGLE_SET;
162  param.compareValue = 32;
163  Timer_B_initCompareMode(TIMER_B0_BASE, &param);
164 
165  //Initialize WDT module in timer interval mode,
166  //with ACLK as source at an interval of 1sec.
167  WDT_A_initIntervalTimer(WDT_A_BASE,
168  WDT_A_CLOCKSOURCE_ACLK,
169  WDT_A_CLOCKDIVIDER_32K);
170 
171  //Enable Watchdog Interupt
172  SFR_clearInterrupt(WDTIE);
173  SFR_enableInterrupt(WDTIE);
174 
175  while (1)
176  {
177  //CONFIGURE PORTS- pass the port_mapping array, start @ P4MAP01, initialize
178  //a single port, allow run-time reconfiguration of port mapping
179  PMAP_initPortsParam initPortsParam = {0};
180  initPortsParam.portMapping = port_mapping;
181  initPortsParam.PxMAPy = (uint8_t *)&P4MAP01;
182  initPortsParam.numberOfPorts = 1;
183  initPortsParam.portMapReconfigure = PMAP_ENABLE_RECONFIGURATION;
184  PMAP_initPorts(PMAP_CTRL_BASE, &initPortsParam);
185 
186  //Enter LPM3 w/interrupt
187  __bis_SR_register(LPM3_bits + GIE);
188 
189  //For debugger
190  __no_operation();
191 
192  //Rotate the port map sequence
193  uint8_t tempVariable = port_mapping[0];
194  uint16_t i = 0;
195  for (i = 0; i < 7; i++)
196  {
197  //Rotate port map array
198  port_mapping[i] = port_mapping[i + 1];
199  }
200  port_mapping[7] = tempVariable;
201  }
202 }
203 
204 //******************************************************************************
205 //
206 //This is the Watchdog Timer interrupt service routine
207 //
208 //******************************************************************************
209 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
210 #pragma vector=WDT_VECTOR
211 __interrupt
212 #elif defined(__GNUC__)
213 __attribute__((interrupt(WDT_VECTOR)))
214 #endif
215 void watchdog_timer (void)
216 {
217  __delay_cycles(100);
218 
219  //Exit LPM3
220  __bic_SR_register_on_exit(LPM3_bits);
221 }
222 
MPU_initThreeSegmentsParam param
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)